package uk.org.landeg.euler.problems.unported;

import java.math.BigInteger;

public class Euler053 {
	public static void main(String[] args) {
		int a,b;
		//BigInteger fa, fb;
		System.out.println(factorial(5));
//		fa = new BigInteger("0");
//		fb = new BigInteger("0");
		BigInteger ONE_MILLION = new BigInteger("1000000");
		long biggest = 0;
		int count = 0;
		int n=1;
		BigInteger ncr;
		while (n <= 100) {
			a = n;
			b = n;
			System.out.println("Checking a=" + a);
			while (b <= 100) {
				ncr = ncr(a,b);
				if (biggest < ncr.longValue()) {
					biggest = ncr.longValue();
				}
				if (ncr.max(ONE_MILLION).equals(ncr)) {
					count++;
				}
				System.out.print(".");
				b++;
			}
			
			System.out.println("Biggest So far = " + biggest + ", count=" + count);			
			n++; 
		}
		System.out.println(count);
	}
	
	static BigInteger factorial (int l) {
		BigInteger ret= new BigInteger("1");
		while (l >0) {
			ret=ret.multiply(new BigInteger(l + ""));
			l--;
		}
		return ret;
	}
	
	static BigInteger ncr (int n, int r) {
		return (factorial(n).divide(factorial(r)).divide(factorial(n-r)));
	}
}
